import { Command } from "commander";
import { Client, Wallet, Wallet as XrplWallet } from "xrpl";
import { Log, LogStatus, LogType } from "../util/Logger";

const program = new Command("create-xrp-wallet")
    .option("-f, --faucet <value>", "The faucet to connect with", "sidechain-faucet.devnet.rippletest.net")
    .option("-n, --node <value>", "The network node", "wss://sidechain-net1.devnet.rippletest.net")
    .action(async ({ faucet, node }) => {
        try {
            Log(LogType.Tool, LogStatus.ToDo, `Creating wallet...`);
            const client = new Client(node);
            await client.connect();
            const wallet = Wallet.generate();
            await client.fundWallet({ address: wallet.address, classicAddress: wallet.address } as XrplWallet, {
                faucetHost: faucet,
            });
            Log(LogType.Tool, LogStatus.Done, `Wallet created and funded with address ${wallet.address} seed ${wallet.seed}`);
        } catch (error) {
            console.log(error);
            process.exit(1);
        }
        process.exit(0);
    });
export default program;
